/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg1;

import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Objects of this class represent patients in the domain model.
 * @author Nick
 */
public class Patient {
    //Name of the patient
    private String name;
    //Bed Id of the patient
    private int bedId;
    //Whether or not the patient is in critical condition
    private boolean isCritical;
    //The date of admission into the hospital
    private Date dateOfAdmissions;
    //The gender of the patient
    private String gender;
    //The age of the patient
    private Date dateOfBirth;
    //The Unique ID of the patient
    private int id;
    //Constructor for a new patient
    public Patient(String name, boolean isCritical, Date dateOfAdmissions,
            String gender, Date dateOfBirth, int id, int bedId) {
        this.name = name;
        this.isCritical = isCritical;
        this.dateOfAdmissions = dateOfAdmissions;
        this.gender = gender;
        this.dateOfBirth = dateOfBirth;
        this.id = id;
        this.bedId = bedId;
    }

    /**
     * @return the name of the patient
     */
    public String getName() {
        return name;
    }

    /**
     * @return the status of the patient
     */
    public boolean isCritical() {
        return isCritical;
    }
    
    /**
     * @return the dateOfAdmissions of the patient
     */
    public String getDateOfAdmissions() {
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        return dateFormat.format(dateOfAdmissions);
    }

    /**
     * @return the timeOfAdmissions of the patient
     */
    public String getTimeOfAdmissions() {
        DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
        return timeFormat.format(dateOfAdmissions);
    }

    /**
     * @return the gender of the patient
     */
    public String getGender() {
        return gender;
    }

    /**
     * @return the age of the patient
     */
    public Date getDateOfBirth() {
        return dateOfBirth;
    }
    
    /**
     * returns the date of birth of the patient as a string for display
     * @return 
     */
    public String getDateOfBirthAsString() {
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        return dateFormat.format(dateOfBirth);
    }

    /**
     * @return the id of the patient
     */
    public int getId() {
        return id;
    }
    
    /**
     * @return the Bedid of the patient
     */
    public int getBedId() {
        return bedId;
    }
    
    /**
     * sets the bedId of the patient
     */
    public void setBedId(int newId) {
        bedId = newId;
    }
    
    /**
     * gets a string representation of the patient
     * @return 
     */
    public String toString() {
        return name + "(" + id + ")";
    }

    /**
     * @param isCritical the isCritical to set
     */
    public void setIsCritical(boolean isCritical) {
        this.isCritical = isCritical;
    }
    
    /**
     * returns a new string with all the necessary information to save the patient
     * @return 
     */
    public String getSaveString() {
        String saveString = "";
        saveString += "Id:" + id + ",";
        saveString += "Name:" + name + ",";
        
        String realDateOfBirth = dateOfBirth.getDate() + "";
        if(dateOfBirth.getDate() < 10) {
            realDateOfBirth = "0" + dateOfBirth.getDate();
        }
        String realMonthOfBirth = (dateOfBirth.getMonth() + 1) + "";
        if((dateOfBirth.getMonth() + 1) < 10) {
            realMonthOfBirth = "0" + (dateOfBirth.getMonth() + 1);
        }
        
        String realDateOfAdmissions = dateOfAdmissions.getDate() + "";
        if(dateOfAdmissions.getDate() < 10) {
            realDateOfAdmissions = "0" + dateOfAdmissions.getDate();
        }
        String realMonthOfAdmissions = (dateOfAdmissions.getMonth() + 1) + "";
        if((dateOfAdmissions.getMonth() + 1) < 10) {
            realMonthOfAdmissions = "0" + (dateOfAdmissions.getMonth() + 1);
        }
        String year = (dateOfBirth.getYear() + 1900) + "";
        if(dateOfBirth.getYear() + 1900 < 1000) {
            year = "0000";
        }
        saveString += "DateOfBirth:" + realMonthOfBirth + realDateOfBirth + year + ",";
        saveString += "DateOfAdmissions:" + realMonthOfAdmissions + realDateOfAdmissions + (dateOfAdmissions.getYear() + 1900) + ",";
        saveString += "Gender:" + gender + ",";
        saveString += "BedId:" + bedId + ",";
        saveString += "IsCritical:" + isCritical;
        return saveString;
    }
}
